#!/bin/bash
# in all ab calls we'll gather 10 percent more values than necessary and ignore them when
# graphing due to a bug in ab that leads to skewed metrics
# for appache comparison of app/ vs / (static) vs /app/happy/ (db)
ab -n 11000 -c 20 -g app-metrics.plot http://localhost/app
ab -n 11000 -c 20 -g slash-metrics.plot http://localhost/
ab -n 11000 -c 20 -g happy-metrics.plot http://localhost/app/happy
./app-slash-happy-gen.sh 10000 20 app-metrics.plot slash-metrics.plot happy-metrics.plot

ab -n 11000 -c 40 -g app-metrics.plot http://localhost/app
ab -n 11000 -c 40 -g slash-metrics.plot http://localhost/
ab -n 11000 -c 40 -g happy-metrics.plot http://localhost/app/happy
./app-slash-happy-gen.sh 10000 40 app-metrics.plot slash-metrics.plot happy-metrics.plot

ab -n 11000 -c 60 -g app-metrics.plot http://localhost/app
ab -n 11000 -c 60 -g slash-metrics.plot http://localhost/
ab -n 11000 -c 60 -g happy-metrics.plot http://localhost/app/happy
./app-slash-happy-gen.sh 10000 60 app-metrics.plot slash-metrics.plot happy-metrics.plot

# now generate some comparisons agains /app/happy with memory constraints
# 1gb
./set-mem-limit.sh 1073741824
ab -n 1100 -c 50 -g mem-1-metrics.plot http://localhost/app/happy
./clear-mem-limit.sh

# 1/2 gb
./set-mem-limit.sh 536870912
ab -n 1100 -c 50 -g mem-2-metrics.plot http://localhost/app/happy
./clear-mem-limit.sh

# 1/4 gb
./set-mem-limit.sh 268435456
ab -n 1100 -c 50 -g mem-3-metrics.plot http://localhost/app/happy
./clear-mem-limit.sh

./mem-compare-gen.sh mem-1-metrics.plot mem-2-metrics.plot mem-3-metrics.plot

# now generate some comparisons agains /app/happy with cpu constraints
# 100 percent
ab -n 1100 -c 50 -g cpu-1-metrics.plot http://localhost/app/happy

# 25 percent
./set-cpu-limit.sh 256
ab -n 1100 -c 50 -g cpu-2-metrics.plot http://localhost/app/happy
./clear-cpu-limit.sh

# ~5 percent
./set-cpu-limit.sh 51
ab -n 1100 -c 50 -g cpu-3-metrics.plot http://localhost/app/happy
./clear-cpu-limit.sh

./cpu-compare-gen.sh cpu-1-metrics.plot cpu-2-metrics.plot cpu-3-metrics.plot


# Display Results in midori
midori performance_results.html

# Exit
exit